home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Libraries / TurboTCP 2.0.1 / TurboTCP source / CTelnetInterp.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-02  |  5.0 KB  |  149 lines  |  [TEXT/MPCC]

  1. /*
  2. ** CTelnetInterp.h
  3. **
  4. **    TurboTCP support library
  5. **    Generic Telnet protocol interpreter
  6. **
  7. **    Copyright © 1993-94, FrostByte Design / Eric Scouten
  8. **
  9. */
  10.  
  11.  
  12. #pragma once
  13.  
  14. #include "TCL.h"
  15. #include "CTCPEndpoint.h"
  16. #include "Telnet.protocol.h"
  17.  
  18.  
  19. // state variable for the Telnet command parser
  20.  
  21. typedef unsigned char uchar;
  22. typedef enum TelnetState {
  23.     normalChar,                            // interpret as character
  24.     gotIAC,                                // received an IAC character
  25.     gotSB,                                // in subnegotiation
  26.     gotWILL,                                // received a WILL option
  27.     gotWONT,                                // received a WONT option
  28.     gotDO,                                // received a DO option
  29.     gotDONT,                                // received a DONT option
  30.     gotIACinSB                            // received IAC while in SB
  31. } TelnetState;
  32.  
  33. #define sbBfrMax        80                    // max size of subnegotiation buffer
  34. #define lineBfrMax        80                    // max size of line buffer
  35.  
  36.  
  37. /*______________________________________________________________________
  38. **
  39. ** CTelnetInterpreter
  40. **
  41. **    This abstract class is a specialized TCP protocol interpreter. It is a subclass of the
  42. **    CTCPEndpoint mix-in class which implements the basic Telnet protocol. It may be
  43. **    used to implement command-line protocols which are based on the Telnet protocol
  44. **    (i.e., NNTP or FTP).
  45. **
  46. **    This class provides no user interface behaviors and assumes no character-based
  47. **    terminal. You will need to subclass this class to interpret the specific protocol
  48. **    you are implementing. For an example, see the CTelnetTerminal class in the MiniTelnet
  49. **    application.
  50. **
  51. **    NOTE: This class is provided only as a convenience. You need not include it in your project.
  52. **
  53. **    TurboTCP 1.0 NOTE: This class replaces the CTelnetInterpreter class in version 1.0.
  54. **
  55. **
  56. */
  57.  
  58. class CTelnetInterp : public CTCPEndpoint {
  59.  
  60.     TCL_DECLARE_CLASS;
  61.  
  62. protected:
  63.     TelnetState    itsState;                    // current command parser state
  64.     short        sbBfrIndex;                // current index to subnegotiation buffer
  65.     char            sbBfr[sbBfrMax];            // subnegotiation buffer
  66.     short        lineBfrIndex;                // current index to linemode buffer
  67.     char            lineBfr[lineBfrMax];            // linemode buffer
  68.     Boolean        useLineBfr;                // hold all characters until full line received
  69.     Boolean        showDebug;                // show debugging codes
  70.  
  71.  
  72.     // constructor
  73.  
  74. public:
  75.                 CTelnetInterp(unsigned short theDefaultPort,
  76.                     unsigned long recBufferSize = recReceiveSize,
  77.                     unsigned short autoReceiveSize = recAutoRecSize,
  78.                     unsigned short autoReceiveNum = recAutoRecNum,
  79.                     Boolean doUseCName = TRUE);
  80.  
  81.  
  82.     // respond to incoming data
  83.     
  84.         // Override these methods to place characters on the terminal window or
  85.         // interpret them. All Telnet commands are processed before these methods
  86.         // are called (i.e. the character stream sent to these methods is intended
  87.         // directly for the terminal). Both methods *must* be implemented.
  88.         //
  89.         // HandleNVTChar receives a single character.
  90.         // HandleNVTLine receives a pointer to a C string (maximum 81 characters)
  91.         //        which may or may not be terminated by /n or /r.
  92.  
  93.     virtual void    HandleNVTChar(uchar theChar) = 0;
  94.     virtual void    HandleNVTLine(char* theLine) = 0;
  95.     
  96.  
  97.     // Telnet command handling
  98.     
  99.         // If you wish to respond to specific Telnet commands, override these methods.
  100.         // You may ignore any or all of these methods.
  101.  
  102.     virtual void    ReceivedWill(uchar theOption);
  103.                     // default method responds [WONT <option>]
  104.     virtual void    ReceivedWont(uchar theOption) {}
  105.     virtual void    ReceivedDo(uchar theOption);
  106.                     // default method responds [WONT <option>]
  107.     virtual void    ReceivedDont(uchar theOption) {}
  108.     virtual void    ReceivedBRK() {}
  109.     virtual void    ReceivedSynch() {}
  110.     virtual void    ReceivedIP() {}
  111.     virtual void    ReceivedAO() {}
  112.     virtual void    ReceivedAYT() {}
  113.     virtual void    ReceivedEC() {}
  114.     virtual void    ReceivedEL() {}
  115.     virtual void    ReceivedGA() {}
  116.     virtual void    ReceivedSB(uchar theChar);
  117.                     // default method collects characters until [IAC SE] is received
  118.                     // (characters are ignored unless ReceivedSE is overriden)
  119.     virtual void    ReceivedSE() {}
  120.  
  121.  
  122.     // debugging methods
  123.  
  124.         // Override these methods if you wish to use the debugging features built into
  125.         // this class. If the showDebug field is set, you these methods will receive
  126.         // notifications such as [IAC EC] when Telnet commands are received over
  127.         // the data stream.
  128.         //
  129.         // These methods were useful to me in debugging the implementation of various Telnet
  130.         // options. In a terminal-based method (such as MiniTelnet’s CTelnetTerminal), these
  131.         // should be hooked up to routines that print the relevant data to the display screen.
  132.         //
  133.         //    PrintDebugStr() should display a C string to the terminal.
  134.         //    PrintDebugCharNum() should display a bracketed character number to
  135.         //        the terminal (i.e. if you call PrintDebugCharNum('!', '[', ']'), [33]
  136.         //        should be written to the terminal).
  137.  
  138.     virtual void    PrintDebugStr(char* theDebugStr) {}
  139.     virtual void    PrintDebugCharNum(char theChar, char leftBracket, char rightBracket) {}
  140.  
  141.  
  142.     // respond to incoming data — do not override these methods
  143.     
  144. private:
  145.     virtual void    HandleDataArrived(void* theData, unsigned short theDataSize, Boolean isUrgent);
  146.     virtual void    ReceivedIAC(uchar theCommand);
  147.  
  148. };
  149.